﻿<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/common/_taglibs.jsp"%>
<%@ include file="/common/_meta.jsp"%>
<title>资源管理</title>
<meta name="keywords" content="cms-simple CMS后台管理系统">
<meta name="description" content="cms-simple CMS后台管理系统">
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 权限资源 <span class="c-gray en">&gt;</span> 权限资源列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">
	<div class="text-c bk-gray"> 
		<ul id="Huifold1" class="Huifold">
		  <li class="item">
		    <h4><b>+</b></h4>
		    <div class="info">
		    	<form action="${ctx }/sys/queryResource" method="post">
		    		<div class="text-c"> 
		    			<span class="select-box inline">
						<select class="select" size="1" name="type">
							<option value="" selected>资源类型</option>
							<option value="1">菜单</option>
							<option value="2">方法</option>
						</select>
						</span>
						<span class="select-box inline">
						<select class="select" size="1" name="status">
							<option value="" selected>资源状态</option>
							<option value="1">启用</option>
							<option value="2">禁止</option>
						</select>
						</span> 日期范围：
						<input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'logmax\')||\'%y-%M-%d\'}'})" id="logmin" class="input-text Wdate" style="width:120px;">
						-
						<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'logmin\')}',maxDate:'%y-%M-%d'})" id="logmax" class="input-text Wdate" style="width:120px;">
						<input type="text" class="input-text" style="width:250px" placeholder="输入资源名称" name="name">
						<button class="btn btn-success" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜权限</button>
					</div>
		    	</form>
		    </div>
		  </li>
		</ul>
	</div>
	<div class="cl pd-5 bg-1 bk-gray mt-20"> 
		<span class="l">
			<a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> 
			<a href="javascript:;" onclick="admin_edit('添加资源',0)" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加资源</a>
		</span> 
		<span class="r">总条数:${pageInfo.total} 总页数:${pageInfo.pages} 当前页:${pageInfo.pageNum}</span> 
	</div>
	<div class="mt-20">
		<table class="table table-border table-bordered table-hover table-bg table-sort">
			<thead>
				<tr>
					<th scope="col" colspan="9">权限列表</th>
				</tr>
				<tr class="text-c">
					<th width="25"><input type="checkbox" name="" value=""></th>
					<th width="150">权限名称</th>
					<th width="90">描述</th>
					<th width="90">资源类型</th>
					<th width="90">资源地址</th>
					<th width="100">是否已启用</th>
					<th width="80">排序</th>
					<th width="100">创建时间</th>
					<th width="100">操作</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${pageInfo.list != null }">
					<c:forEach items="${pageInfo.list }" var="resource">
					    <tr class="text-c">
						<td><input type="checkbox" value="${resource.id }" name="id"></td>
						<td>${resource.name }</td>
						<td>${resource.description }</td>
						<td>
							<c:if test="${resource.type == 1}">
								<span style="color:red;">菜单</span>
							</c:if>
							<c:if test="${resource.type == 2}">
								方法
							</c:if>
						</td>
						<td>${resource.url }</td>
						<td class="td-status">
							<c:choose>
								<c:when test="${resource.status == 1}">
									<span class="label label-success radius">已启用</span>
								</c:when>
								<c:when test="${resource.status == 2}">
									<span class="label label-default radius">已禁用</span>
								</c:when>
							</c:choose>
						</td>
						<td>${resource.sort }</td>
						<td>${resource.createDate }</td>
						<td class="td-manage">
							<c:choose>
								<c:when test="${resource.status == 1}">
									<a style="text-decoration:none" onClick="admin_stop(this,'${resource.id }', 2)" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a> 
								</c:when>
								<c:when test="${resource.status == 2}">
									<a style="text-decoration:none" onClick="admin_start(this,'${resource.id }', 1)" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a> 
								</c:when>
							</c:choose>
							<a title="编辑" href="javascript:;" onclick="admin_edit('资源编辑','${resource.id }')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> 
							<a title="删除" href="javascript:;" onclick="admin_del(this,'${resource.id }')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>
						</td>
						</tr>
					</c:forEach>
				</c:if>
			</tbody>
		</table>
	</div>
	<%@ include file="/common/_pageInfo.jsp"%>
</div>
<%@ include file="/common/_footer.jsp"%>
<script type="text/javascript">
/*管理员-编辑*/
function admin_edit(title,id){
	var url = "${ctx}/sys/loadResource?resourceId="+id;
	layer_show(title,url,width,height);
}
/*管理员-删除*/
function admin_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
		   type: "POST",
		   url: "${ctx}/sys/delResource",
		   data: {"resourceId":id},
		   success: function(msg){
			   $(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
		   }
		});
	});
}

/*管理员-停用*/
function admin_stop(obj,id,status){
	layer.confirm('确认要停用吗？',function(index){
		$.ajax({
		   type: "POST",
		   url: "${ctx}/sys/changeResourceStatus",
		   data: {"resourceId":id, "status":status},
		   success: function(msg){
				$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_start(this,'+id+',1)" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-default radius">已禁用</span>');
				$(obj).remove();
				layer.msg('已停用!',{icon: 5,time:1000});
		   }
		});
	});
}

/*管理员-启用*/
function admin_start(obj,id,status){
	layer.confirm('确认要启用吗？',function(index){
		$.ajax({
		   type: "POST",
		   url: "${ctx}/sys/changeResourceStatus",
		   data: {"resourceId":id, "status":status},
		   success: function(msg){
			   $(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_stop(this,'+id+',2)" href="javascript:;" title="停用" style="text-decoration:none"><i class="Hui-iconfont">&#xe631;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
				$(obj).remove();
				layer.msg('已启用!', {icon: 6,time:1000});
		   }
		});
	});
}
</script>
</body>
</html>
